<?php
namespace Components\Account\User;

class TeamService {
	public function getNewModel($parameters = []) {
		return new Team\Model($parameters);
	}

	public function findFirst($parameters = []) {
		$model = Team\Model::findFirst($parameters);
		if(!$model) {
			return ['code' => -1, 'message' => '数据不存在或已删除'];
		}
		
		$model -> data = json_decode($model -> data, true);

		return ['code' => 0, 'model'=>$model];
	}

	public function find($parameters = []) {
		$models = Team\Model::find($parameters);
		if(!$models -> valid()) {
			return ['code' => -1, 'message' => '数据不存在或已删除'];
		}

		return ['code' => 0, 'models'=>$models];
	}

	public function pager($parameters = [], $limit = 10, $page = 1) {
		return ['code' => 0, 'pager'=>(new \Phalcon\Paginator\Adapter\QueryBuilder([
			'builder' => (new \Phalcon\Mvc\Model\Query\Builder($parameters)) -> from(__NAMESPACE__ . '\\Model'),
			'limit' => $limit,
			'page' => $page
		])) -> getPaginate()];
	}
}